package cn.wolfcode.luowowo.comment.service.impl;

import cn.wolfcode.luowowo.comment.domain.TravelComment;
import cn.wolfcode.luowowo.comment.repository.TravelCommentMongoRepository;
import cn.wolfcode.luowowo.comment.service.ITravelCommentService;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Date;
import java.util.List;
import java.util.Optional;

@Service
public class TravelCommentServiceImpl implements ITravelCommentService {

@Autowired
private TravelCommentMongoRepository repository;



    public TravelComment save(TravelComment entity) {
//        处理评论信息
        if(TravelComment.TRAVEL_COMMENT_TYPE.equals(entity.getType())){
            //当前评论属于回复评论
            //根据引用评论的id取查询原评论信息.
            Optional<TravelComment> op = repository.findById(entity.getRefComment().getId());
            if(op.isPresent()){
                //设置引用对象的信息,牛逼.
                entity.setRefComment(op.get());
            }
        }

        entity.setCreateTime(new Date());
        repository.save(entity);
        return entity;

    }

    public List<TravelComment> listTavelId(Long TravelId) {

        return repository.findByTravelId(TravelId);
    }
}
